package com.xfcycle.zebrabikegp.util;

import android.app.Activity;
import android.util.DisplayMetrics;

import java.util.HashMap;
import java.util.Map;

/**
 * 和手机屏幕相关的工具类
 * Created by xFcycle on 2017/5/25.
 */

public class ScreenUtil {

    /**
     * 获取当前屏幕的宽高
     * @param activity 当前页面的activity
     * @return 返回一个Map对象 key分别为 "screenWidth" 和 "screenHeight"
     */
    public static Map<String, Integer> getScreenSize(Activity activity){

        //定义DisplayMetrics对象
        DisplayMetrics dm = new DisplayMetrics();
        //取得窗口属性
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

        //获得窗口宽高
        int screenWidth = dm.widthPixels;
        int screenHeight = dm.heightPixels;

        //返回取到的窗口宽高
        Map<String,Integer> params = new HashMap<>();
        params.put("screenWidth",screenWidth);
        params.put("screenHeight",screenHeight);
        return params;
    }
}
